<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Dreamer Blog - 后台登录</title>
    <!-- Custom Styles-->
    <link th:href="@{/resource/css/custom-login.css}" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" th:href="@{/resource/js/jQueryMessage/css/message.skin.css}" />
</head>

<body>
	<canvas></canvas>
	<div class="login">
		<h1>在线考试系统</h1>
		<form method="post" id="loginForm">
			<div class="login-form-row">
				<input type="text" id="account" placeholder="用户名" required="required" />
			</div>
			<div class="login-form-row">
				<input type="password" id="password" placeholder="密码" required="required" />
			</div>
			<!--<div class="login-form-row">-->
				<!--<div class="login-form-vcode"><img alt="图片验证码" width="100" height="39" src="" id="vcode"></div>-->
				<!--<div class="login-form-vcode-input"><input type="text" name="vcode" placeholder="验证码" required="required" /></div>-->
				<!--<div class="clear"></div>-->
			<!--</div>-->
			<div class="login-form-row">
				<button type="button"  id="loginBtn" class="btn btn-primary btn-block btn-large" >登录</button>
			</div>
		</form>
	</div>
		<div class="copyright">
			仅供学习.....
		</div>
	<script type="text/javascript" th:src="@{/resource/js/jquery.min.js}"></script>
	<script type="text/javascript" th:src="@{/resource/js/jQueryMessage/js/jquery.plugin.message.js}"></script>
    <script type="text/javascript" th:src="@{/resource/js/vector.js}"></script>
    <script type="text/javascript">
		if (window.frames.length != parent.frames.length) {
			window.parent.location.href = "/admin/u/logout";
		}
	    $(function () {
	    	$('#account').focus();

	    	$("#loginForm").keyup(function(event){
	    		if(event.keyCode ==13){
	    			login();
	    		}
	    	});

	    	$("#loginBtn").on("click", login);
		});
	    function login(){
			var account = $('#account').val();
			var password = $('#password').val();
			var loginInfo = {
                "account" : account,
                "password" : password
            };
			console.log(loginInfo);
            var contextPath = [[@{/}]];
			$.ajax({
				url : contextPath + "doLogin",
				contentType : 'application/x-www-form-urlencoded',
				data : loginInfo,
				type : "POST",
				dataType : "JSON",
				success : function(result) {
					console.log(result);
					if(result.success){
						sessionStorage.setItem("dreamer-cms-user", JSON.stringify(result.data));
						setTimeout(function() {
							//登录返回
							window.location.href = contextPath + "index";
						}, 500);
					}else{
						$("body").MessageBox({
							type: 'error',
							message:result.info,
							timeout:3000,
							callbak:null
						});
					}
				}
			});
		}
	</script>
</body>
</html>